package io.receive;

import org.eclipse.paho.client.mqttv3.IMqttMessageListener;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttMessage;

/**
 * @author CZF
 * @create 2023-02-26 18:55
 */
public class SubMessageListener implements IMqttMessageListener {
    private String id;
    private MqttClient mqttClient;
    private String topic;

    public SubMessageListener() {
    }

    public SubMessageListener(String id, MqttClient mqttClient, String topic) {
        this.id = id;
        this.mqttClient = mqttClient;
        this.topic = topic;
    }

    @Override
    public void messageArrived(String topic, MqttMessage mqttMessage) throws Exception {
        System.out.println("接收消息主题 : " + topic);
        System.out.println("接收消息Qos : " + mqttMessage.getQos());
        System.out.println("接收消息 " + ": " + new String(mqttMessage.getPayload()));
    }




}